home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OTSimpleServerHTTP / EnableIPReuseAddrSample.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.3 KB  |  79 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        EnableIPReuseAddrSample.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Rich Kubota    
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/23/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #include <OpenTransport.h>            // open transport files            
  24. #include <OpenTptInternet.h>
  25.  
  26. OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode);
  27.  
  28. /* Input: ep - endpointref on which to negotiate the option
  29.             enableReuseIPMode - desired option setting - true/false
  30.    Return: kOTNoError indicates that the option was successfully negotiated
  31.                OSStatus is an error if < 0, otherwise, the status field is
  32.                returned and is > 0.
  33.        
  34.        IMPORTANT NOTE: The endpoint is assumed to be in synchronous more, otherwise
  35.                this code will not function as desired
  36. */
  37.  
  38.  
  39. OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode)
  40.  
  41. {
  42.     UInt8        buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  43.     TOption*    opt;                        // option ptr to make items easier to access
  44.     TOptMgmt    req;
  45.     TOptMgmt    ret;
  46.     OSStatus    err;
  47.     
  48.     if (!OTIsSynchronous(ep))
  49.     {
  50.         return (-1);
  51.     }
  52.     opt = (TOption*)buf;                    // set option ptr to buffer
  53.     req.opt.buf    = buf;
  54.     req.opt.len    = sizeof(buf);
  55.     req.flags    = T_NEGOTIATE;                // negotiate for option
  56.  
  57.     ret.opt.buf = buf;
  58.     ret.opt.maxlen = kOTFourByteOptionSize;
  59.  
  60.     opt->level    = INET_IP;                    // dealing with an IP Level function
  61.     opt->name    = IP_REUSEADDR;
  62.     opt->len    = kOTFourByteOptionSize;
  63.     opt->status = 0;
  64.     *(UInt32*)opt->value = enableReuseIPMode;        // set the desired option level, true or false
  65.  
  66.     err = OTOptionManagement(ep, &req, &ret);
  67.     
  68.         // if no error then return the option status value
  69.     if (err == kOTNoError)
  70.     {
  71.         if (opt->status != T_SUCCESS)
  72.             err = opt->status;
  73.         else
  74.             err = kOTNoError;
  75.     }
  76.                 
  77.     return err;
  78. }
  79.